package com.codingvip.queue;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 *
 * @author hansongtao
 */
public class Stack2Queue {
	Stack<Integer> stack1 = new Stack();
	Stack<Integer> stack2 = new Stack();
    //入栈
    public void push(int value) {
		stack1.push(value);
    }
    public Integer  pop() {
		if (stack1.isEmpty()) {
			return -1;
		}
		while (stack1.size() >1) {
			stack2.push(stack1.pop());
		}
		int value = stack1.pop();
		while (!stack2.isEmpty()) {
			stack1.push(stack2.pop());
		}

		return value;

	}

	public static void main(String[] args) {
		Stack2Queue s=new Stack2Queue();
		s.push(1);
		s.push(2);
		s.push(3);
		System.out.println("出队列："+s.pop());
		s.push(4);

		System.out.println("出队列："+s.pop());
		System.out.println("出队列："+s.pop());

	}

}

